package com.peng.mvvm_wan.adapters

import android.os.Build
import android.text.Html
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.peng.mvvm_wan.R
import com.peng.mvvm_wan.beans.ArticleBean

class SearchAdapter : BaseQuickAdapter<ArticleBean, BaseViewHolder>(
    R.layout.item_search_result,
    mutableListOf()
), LoadMoreModule {
    override fun convert(helper: BaseViewHolder, item: ArticleBean) {
        val title = item.title?.replace(
            "<em class='highlight'",
            "<em class='highlight'><font color='#FF0000'"
        )?.replace("/em>", "/font></em>") ?: "无"
        val titleSpan = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            Html.fromHtml(title, Html.FROM_HTML_MODE_LEGACY)

        } else {
            Html.fromHtml(title)

        }
        helper.setText(R.id.tv_title, titleSpan)
        helper.setText(R.id.tv_shareUser, item.shareUser ?: "无")

    }

}